package com.luo.bak;

import com.luo.pojo.User;
import org.springframework.web.bind.annotation.*;

//@RestController
//@RequestMapping("/user1")
public class UserController_bak {

    public UserController_bak() {
        System.out.println("UserController构造函数");
    }

    @RequestMapping(value = "/insert", method = RequestMethod.GET)
    public String insertUser(){

        return "insertUser";
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public String updateUser(){
        return "updateUser";
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public String deleteUser(){
        return "deleteUser";
    }

    @RequestMapping(value = "/test00",method = RequestMethod.GET)
    public String test00(){
        //可以传参，但不处理
        return "test00";
    }

    @RequestMapping(value = "/test01",method = RequestMethod.GET)
    public String test01(String username){
        //这样定义的参数可传可不传，并且用户传递的参数只接收一个
        return username;
    }
    @RequestMapping(value = "/test02",method = RequestMethod.GET)
    public String test02(String username,String password){
        //这样定义的参数可传可不传，并且用户传递的参数只接收两个，并且名字必须一样
        return username+password;
    }
    @RequestMapping(value = "/test03",method = RequestMethod.GET)
    public String test03(@RequestParam String username){
        //这样定义的参数必须传递username，否则拒绝
             return username;
    }
    // @RequestParam 请求参数注解
    @RequestMapping(value = "/test04",method = RequestMethod.GET)
    public String test04(@RequestParam String username,@RequestParam String password){
        //这样定义的参数必须传递username和password，否则拒绝
        return username+password;
    }

    @RequestMapping(value = "/test05",method = RequestMethod.GET)
    public String test05(@RequestParam String username, String password){
        //这样定义的参数必须传递username,password可传可不传
        return username+password;
    }
    @RequestMapping(value = "/test06",method = RequestMethod.GET)
    public String test06(@RequestParam(required = false) String username, String password){
        //@RequestParam(required = false) 等于没写，和不写注解是一样的
        return username+password;
    }
    @RequestMapping(value = "/test07",method = RequestMethod.GET)
    public String test07(@RequestParam(required = false,name = "uname") String username, String password){
        //如果要传，则username名字为uname
        return username+password;
    }

    @RequestMapping(value = "/test08",method = RequestMethod.GET)
    public String test08(@RequestParam(name = "uname",defaultValue = "xl") String username, String password){
        //如果要传，则username名字为uname,默认xl
        return username+password;
    }

    @RequestMapping(value = "/test09",method = RequestMethod.GET)
    public String test09(User user){
        //如果要传，则username名字为uname,默认xl
        return user.toString();
    }
    @RequestMapping(value = "/test10",method = RequestMethod.GET)
    public String test10(@RequestParam User user){
        //不能实现必传
        return user.toString();
    }

    @RequestMapping(value = "/test11",method = RequestMethod.POST)
    public String test11(@RequestBody User user){
        //传JSON
        return user.toString();
    }

//    @Autowired
//    private UserService userService;
//
//    @RequestMapping(value = "/selectUser",
//             method = RequestMethod.GET,RequestMethod.POST)
//    public String selectUser(ModelMap modelMap) {
//        System.out.println("UserAction -------------------------- selectUser");
//
//        List<User> list = new ArrayList<>();
//        User user = new User();
//        user.setUsername("kkk");
//        user.setPassword("3330");
//        list.add(user);
//
//        user = new User();
//        user.setUsername("jjj");
//        user.setPassword("4440");
//        list.add(user);
//
//        user = new User();
//        user.setUsername("aaa");
//        user.setPassword("5550");
//        list.add(user);
//
//        try {
//            System.out.println("--------");
////            userService.insertUser(list);
//        } catch (Exception e) {
//            System.out.println("---------------------------------------------------sql出错");
//            e.printStackTrace();
//        }
//
////        userService.updateUser(user);
//        modelMap.addAttribute("list_user", "en~~~");
//        return "success";
//    }
}
